// pages/main/main.js
const app = getApp()
const G = app.globalData
const D = G.datas
const F = require('../../js/functions.js')
const menus = require('../../res/datas.js').mainmenus

Page({
	// 借壳函数
	navigate: function(e) { F.navigate(this, e) },

	/**
	 * 页面的初始数据
	 */
	data: {
		emp: {},
		state: {},
		curstate: 0,
		menus: [],
		curmenu: -1,
	},
	
	choosemenu: function(e) {
		let curmenu = this.data.curmenu
		let cursubmenu = -1
		let id = e.currentTarget.dataset.id
		if (curmenu != -1) {
			if (id == -1) {
				curmenu = -1
			} else {
				cursubmenu = id
				this.actions(curmenu, cursubmenu)
			}
		} else {
			curmenu = id
			if (curmenu == -2) {
				console.log('next month')
				
			} else {
				console.log(this.data.menus[curmenu].name)
			}
			
		}
		this.setData({
			curmenu
		})
		
	},
	
	actions: function(curmenu, cursubmenu) {
		
		console.log('curmenu = ', curmenu)
		console.log('cursubmenu = ', cursubmenu)
		console.log(this.data.menus[curmenu].submenus[cursubmenu].name)
		
	},

	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad: function (options) {
		this.setData({
			state: D.states[0],
			emp: D.emp,
			menus: menus,
		})
	},

	/**
	 * 生命周期函数--监听页面初次渲染完成
	 */
	onReady: function () {

	},

	/**
	 * 生命周期函数--监听页面显示
	 */
	onShow: function () {
		if (wx.canIUse('hideHomeButton')){
			wx.hideHomeButton({})
		}
	},

	/**
	 * 生命周期函数--监听页面隐藏
	 */
	onHide: function () {

	},

	/**
	 * 生命周期函数--监听页面卸载
	 */
	onUnload: function () {

	},

	/**
	 * 页面相关事件处理函数--监听用户下拉动作
	 */
	onPullDownRefresh: function () {

	},

	/**
	 * 页面上拉触底事件的处理函数
	 */
	onReachBottom: function () {

	},

	/**
	 * 用户点击右上角分享
	 */
	onShareAppMessage: function () {

	}
})

